package fr.unice.polytech.chord.samples.managers;

import java.util.LinkedList;
import java.util.List;

import fr.unice.polytech.chord.core.Tracker;
import fr.unice.polytech.chord.samples.commands.Command;

/**
 * Manager is an abstract class that must be extends by all managers. A manager
 * is used in order to launch some various kind of tests on a structured
 * peer-to-peer network.
 * 
 * @author Laurent Pellegrino
 * 
 * @version 10/30/2009
 */
public abstract class Manager extends Thread {

	private List<Command> actions = new LinkedList<Command>();

	private boolean isRunning = false;

	private Tracker tracker;

	public Manager(Tracker tracker) {
		this.tracker = tracker;
	}

	public void addAction(Command action) {
		this.actions.add(action);
	}

	public void addAction(Command action, int pos) {
		this.actions.add(pos, action);
	}

	public List<Command> getActions() {
		return this.actions;
	}

	public Tracker getTracker() {
		return this.tracker;
	}

	public boolean isRunning() {
		return this.isRunning;
	}

	public void removeAction(Command action) {
		this.actions.remove(action.getClass().getSimpleName());
	}

	public abstract void run();

	public void startExecution() {
		this.isRunning = true;
		super.start();
	}

	public void stopExecution() {
		this.isRunning = false;
	}
}
